<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>AngularJS中ng-repeat渲染完成事件[2] | jicemoon</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="ng-repeat渲染完成事件此方法与前篇所写不同的是, 此种写法, 每次repeat数组有更新变化(需要重新渲染)时, 都会触发此事件, 调用对应侦听, 但是, Angularjs1.3.0及其以上的版本不支持此种写法.">
<meta property="og:type" content="article">
<meta property="og:title" content="AngularJS中ng-repeat渲染完成事件[2]">
<meta property="og:url" content="http://jicemoon.github.io/2016/06/09/ng-repeat-finish-render-every-time/index.html">
<meta property="og:site_name" content="jicemoon">
<meta property="og:description" content="ng-repeat渲染完成事件此方法与前篇所写不同的是, 此种写法, 每次repeat数组有更新变化(需要重新渲染)时, 都会触发此事件, 调用对应侦听, 但是, Angularjs1.3.0及其以上的版本不支持此种写法.">
<meta property="og:updated_time" content="2016-06-09T14:08:50.447Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="AngularJS中ng-repeat渲染完成事件[2]">
<meta name="twitter:description" content="ng-repeat渲染完成事件此方法与前篇所写不同的是, 此种写法, 每次repeat数组有更新变化(需要重新渲染)时, 都会触发此事件, 调用对应侦听, 但是, Angularjs1.3.0及其以上的版本不支持此种写法.">
  
    <link rel="alternative" href="/atom.xml" title="jicemoon" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
      <link rel="stylesheet" href="//cdn.bootcss.com/animate.css/3.5.0/animate.min.css">
  
  
  <link rel="stylesheet" href="/css/style.css">
  
  <link rel="stylesheet" href="/font-awesome/css/font-awesome.min.css">
  <link rel="apple-touch-icon" href="/apple-touch-icon.png">
  
  
    <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  
  <script src="//cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
  <script>
      var yiliaConfig = {
          fancybox: true,
          animate: true,
          isHome: false,
          isPost: true,
          isArchive: false,
          isTag: false,
          isCategory: false,
          open_in_new: false,
      }
  </script>

  
      <script>
          yiliaConfig.rootUrl = "/";
      </script>
  

  
</head>
<body>
  <div id="container">
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
    <header id="header" class="inner">
        <a href="/" class="profilepic">
            <img src="/img/avatar.png" class="animated zoomIn">
        </a>
        <hgroup>
          <h1 class="header-author"><a href="/">jicemoon</a></h1>
        </hgroup>

        
        <p class="header-subtitle">人生若只如初见</p>
        
                


        
            <div id="switch-btn" class="switch-btn">
                <div class="icon">
                    <div class="icon-ctn">
                        <div class="icon-wrap icon-house" data-idx="0">
                            <div class="birdhouse"></div>
                            <div class="birdhouse_holes"></div>
                        </div>
                        <div class="icon-wrap icon-ribbon hide" data-idx="1">
                            <div class="ribbon"></div>
                        </div>
                        
                        <div class="icon-wrap icon-link hide" data-idx="2">
                            <div class="loopback_l"></div>
                            <div class="loopback_r"></div>
                        </div>
                        
                        
                        <div class="icon-wrap icon-me hide" data-idx="3">
                            <div class="user"></div>
                            <div class="shoulder"></div>
                        </div>
                        
                    </div>
                    
                </div>
                <div class="tips-box hide">
                    <div class="tips-arrow"></div>
                    <ul class="tips-inner">
                        <li>菜单</li>
                        <li>标签</li>
                        
                        <li>友情链接</li>
                        
                        
                        <li>关于我</li>
                        
                    </ul>
                </div>
            </div>
        

        <div id="switch-area" class="switch-area">
            <div class="switch-wrap">
                <section class="switch-part switch-part1">
                    <nav class="header-menu">
                        <ul>
                        
                            <li><a href="/">主页</a></li>
                        
                            <li><a href="/archives/">所有文章</a></li>
                        
                            <li><a href="/tags/">标签</a></li>
                        
                        </ul>
                    </nav>
                    <nav class="header-nav">
                        <ul class="social">
                            
                                <li id="Email"><a class="Email" target="_blank" href="mailto:jicemoon@outlook.com" title="Email"></a></li>
                            
                                <li id="GitHub"><a class="GitHub" target="_blank" href="https://github.com/jicemoon" title="GitHub"></a></li>
                            
                                <li id="简书"><a class="简书" target="_blank" href="http://www.jianshu.com/users/d3babf0c293b/timeline" title="简书"></a></li>
                            
                        </ul>
                    </nav>
                </section>
                
                
                <section class="switch-part switch-part2">
                    <div class="widget tagcloud" id="js-tagcloud">
                        <a href="/tags/AngularJS/" style="font-size: 15px;">AngularJS</a> <a href="/tags/Array/" style="font-size: 10px;">Array</a> <a href="/tags/CSS/" style="font-size: 10px;">CSS</a> <a href="/tags/Canvas/" style="font-size: 10px;">Canvas</a> <a href="/tags/Docs/" style="font-size: 10px;">Docs</a> <a href="/tags/ECMAScript5/" style="font-size: 10px;">ECMAScript5</a> <a href="/tags/HTML5/" style="font-size: 10px;">HTML5</a> <a href="/tags/Hexo/" style="font-size: 10px;">Hexo</a> <a href="/tags/JavaScript/" style="font-size: 20px;">JavaScript</a> <a href="/tags/Javascript/" style="font-size: 15px;">Javascript</a> <a href="/tags/Web/" style="font-size: 20px;">Web</a> <a href="/tags/ng-repeat/" style="font-size: 15px;">ng-repeat</a> <a href="/tags/位运算符/" style="font-size: 10px;">位运算符</a> <a href="/tags/动态加载/" style="font-size: 10px;">动态加载</a> <a href="/tags/垂直居中/" style="font-size: 10px;">垂直居中</a> <a href="/tags/日期格式化/" style="font-size: 10px;">日期格式化</a> <a href="/tags/见缝插针/" style="font-size: 10px;">见缝插针</a>
                    </div>
                </section>
                
                
                
                <section class="switch-part switch-part3">
                    <div id="js-friends">
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="https://hexo.io">Hexo</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="https://pages.github.com/">GitHub</a>
                    
                      <a target="_blank" class="main-nav-link switch-friends-link" href="http://moxfive.xyz/">MOxFIVE</a>
                    
                    </div>
                </section>
                

                
                
                <section class="switch-part switch-part4">
                
                    <div id="js-aboutme">专注于前端</div>
                </section>
                
            </div>
        </div>
    </header>                
</div>
    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
      <div class="overlay">
          <div class="slider-trigger"></div>
          <h1 class="header-author js-mobile-header hide"><a href="/" title="回到主页">jicemoon</a></h1>
      </div>
    <div class="intrude-less">
        <header id="header" class="inner">
            <a href="/" class="profilepic">
                <img src="/img/avatar.png" class="animated zoomIn">
            </a>
            <hgroup>
              <h1 class="header-author"><a href="/" title="回到主页">jicemoon</a></h1>
            </hgroup>
            
            <p class="header-subtitle">人生若只如初见</p>
            
            <nav class="header-menu">
                <ul>
                
                    <li><a href="/">主页</a></li>
                
                    <li><a href="/archives/">所有文章</a></li>
                
                    <li><a href="/tags/">标签</a></li>
                
                <div class="clearfix"></div>
                </ul>
            </nav>
            <nav class="header-nav">
                        <ul class="social">
                            
                                <li id="Email"><a class="Email" target="_blank" href="mailto:jicemoon@outlook.com" title="Email"></a></li>
                            
                                <li id="GitHub"><a class="GitHub" target="_blank" href="https://github.com/jicemoon" title="GitHub"></a></li>
                            
                                <li id="简书"><a class="简书" target="_blank" href="http://www.jianshu.com/users/d3babf0c293b/timeline" title="简书"></a></li>
                            
                        </ul>
            </nav>
        </header>                
    </div>
</nav>
      <div class="body-wrap"><article id="post-ng-repeat-finish-render-every-time" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/2016/06/09/ng-repeat-finish-render-every-time/" class="article-date">
      <time datetime="2016-06-09T13:42:25.000Z" itemprop="datePublished">2016-06-09</time>
</a>
    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      AngularJS中ng-repeat渲染完成事件[2]
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        
    <div class="article-category tagcloud">
    <a class="article-category-link" href="/categories/Web/">Web</a>
    </div>


        
    <div class="article-tag tagcloud">
        <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/AngularJS/">AngularJS</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/JavaScript/">JavaScript</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Web/">Web</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/ng-repeat/">ng-repeat</a></li></ul>
    </div>

        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
          
        <h3 id="ng-repeat渲染完成事件"><a href="#ng-repeat渲染完成事件" class="headerlink" title="ng-repeat渲染完成事件"></a>ng-repeat渲染完成事件</h3><p>此方法与前篇所写不同的是, 此种写法, 每次repeat数组有更新变化(需要重新渲染)时, 都会触发此事件, 调用对应侦听, 但是, Angularjs1.3.0及其以上的版本不支持此种写法.</p>
<a id="more"></a>
<h3 id="核心代码"><a href="#核心代码" class="headerlink" title="核心代码"></a>核心代码</h3><p>原理是使用自定义一个过滤器, 具体代码如下:<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">myApp.filter(<span class="string">'ngRepeatFinishEveryTime'</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$timeout</span>) </span>&#123;</span><br><span class="line">	<span class="keyword">return</span> <span class="function"><span class="keyword">function</span> (<span class="params">data, eventName</span>) </span>&#123;</span><br><span class="line">		<span class="keyword">var</span> me = <span class="keyword">this</span>;</span><br><span class="line">		<span class="keyword">var</span> flagProperty = <span class="string">'__finishedRendering__'</span>;</span><br><span class="line">		<span class="keyword">if</span> (!data) data = &#123;&#125;;</span><br><span class="line">		<span class="keyword">if</span> (!data[flagProperty]) &#123;</span><br><span class="line">		<span class="built_in">Object</span>.defineProperty(data, flagProperty, &#123;</span><br><span class="line">			enumerable: <span class="literal">false</span>,</span><br><span class="line">			configurable: <span class="literal">true</span>,</span><br><span class="line">			writable: <span class="literal">false</span>,</span><br><span class="line">			value: &#123;&#125;</span><br><span class="line">		&#125;);</span><br><span class="line">		$timeout(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">				<span class="keyword">delete</span> data[flagProperty];</span><br><span class="line">				me.$emit(eventName ? eventName : <span class="string">"ngRepeatFinishEveryTime"</span>);</span><br><span class="line">			&#125;, <span class="number">0</span>, <span class="literal">false</span>);</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">return</span> data;</span><br><span class="line">	&#125;;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure></p>
<h3 id="实例"><a href="#实例" class="headerlink" title="实例"></a>实例</h3><p>下面是具体用法实例:<br><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE html&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">"en"</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">style</span>&gt;</span><span class="css"></span><br><span class="line">      <span class="selector-class">.container</span> &#123; <span class="attribute">width</span>: <span class="number">600px</span>; <span class="attribute">margin</span>: auto; &#125;</span><br><span class="line">      <span class="selector-class">.container</span> &gt; <span class="selector-tag">div</span> &#123; <span class="attribute">padding</span>: <span class="number">15px</span>; <span class="attribute">background-color</span>: <span class="number">#6D6D6D</span>; <span class="attribute">color</span>: <span class="number">#ffffff</span>; &#125;</span><br><span class="line">      <span class="selector-tag">table</span> &#123; <span class="attribute">width</span>: <span class="number">100%</span>; <span class="attribute">border</span>: none; <span class="attribute">border-padding</span>: <span class="number">0</span>; <span class="attribute">border-spacing</span>: <span class="number">0</span>; &#125;</span><br><span class="line">	  <span class="selector-tag">table</span> <span class="selector-tag">thead</span>&#123;<span class="attribute">background-color</span>: <span class="number">#c9e4ec</span>;&#125;</span><br><span class="line">      <span class="selector-tag">table</span> <span class="selector-tag">td</span> &#123; <span class="attribute">text-align</span>: center; &#125;</span><br><span class="line">      <span class="selector-tag">table</span> <span class="selector-tag">td</span> <span class="selector-class">.button</span> &#123; <span class="attribute">cursor</span>: pointer; <span class="attribute">color</span>: <span class="number">#571d00</span>; <span class="attribute">font-weight</span>: bold; &#125;</span><br><span class="line">      <span class="selector-tag">table</span> <span class="selector-tag">tr</span> &#123; <span class="attribute">height</span>: <span class="number">2.5em</span>; <span class="attribute">vertical-align</span>: middle;&#125;</span><br><span class="line">      <span class="selector-tag">table</span> <span class="selector-tag">tbody</span> <span class="selector-tag">tr</span><span class="selector-pseudo">:nth-child(2n+1)</span> &#123; <span class="attribute">background-color</span>: <span class="number">#f0f0f0</span>; &#125;</span><br><span class="line">      <span class="selector-tag">table</span> <span class="selector-tag">tbody</span> <span class="selector-tag">tr</span><span class="selector-pseudo">:nth-child(2n)</span> &#123; <span class="attribute">background-color</span>: <span class="number">#f0e0ff</span>; &#125;</span><br><span class="line">      <span class="selector-tag">table</span> <span class="selector-tag">tfoot</span> &#123; <span class="attribute">background-color</span>: <span class="number">#ffd9c2</span>; &#125;</span><br><span class="line">    </span><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span><span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"http://apps.bdimg.com/libs/angular.js/1.2.9/angular.min.js"</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">body</span> <span class="attr">ng-app</span>=<span class="string">"myApp"</span> <span class="attr">ng-controller</span>=<span class="string">"userCtrl"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"container"</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">table</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">thead</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">tr</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">th</span>&gt;</span>索引<span class="tag">&lt;/<span class="name">th</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">th</span>&gt;</span>学号<span class="tag">&lt;/<span class="name">th</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">th</span>&gt;</span>姓名<span class="tag">&lt;/<span class="name">th</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">th</span>&gt;</span>性别<span class="tag">&lt;/<span class="name">th</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">th</span>&gt;</span>年龄<span class="tag">&lt;/<span class="name">th</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">th</span>&gt;</span>操作<span class="tag">&lt;/<span class="name">th</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;/<span class="name">tr</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">thead</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">tbody</span> <span class="attr">repeat-id</span>=<span class="string">"r0"</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">tr</span> <span class="attr">ng-repeat</span>=<span class="string">"(si,stu) in students=(persons|orderBy:'sort')|ngRepeatFinishEveryTime:'studentsRepeatFinish' track by $index"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">td</span> <span class="attr">ng-bind</span>=<span class="string">"si+1"</span>&gt;</span><span class="tag">&lt;/<span class="name">td</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">td</span> <span class="attr">ng-bind</span>=<span class="string">"stu.id"</span>&gt;</span><span class="tag">&lt;/<span class="name">td</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">td</span> <span class="attr">ng-bind</span>=<span class="string">"stu.name"</span>&gt;</span><span class="tag">&lt;/<span class="name">td</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">td</span> <span class="attr">ng-bind</span>=<span class="string">"stu.gender"</span>&gt;</span><span class="tag">&lt;/<span class="name">td</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">td</span> <span class="attr">ng-bind</span>=<span class="string">"stu.age"</span>&gt;</span><span class="tag">&lt;/<span class="name">td</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">td</span>&gt;</span></span><br><span class="line">              <span class="tag">&lt;<span class="name">span</span> <span class="attr">class</span>=<span class="string">"button"</span> <span class="attr">ng-click</span>=<span class="string">"changeSort(students, si, -1, 'sort')"</span> <span class="attr">ng-if</span>=<span class="string">"!$first"</span>&gt;</span>上移<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">              <span class="tag">&lt;<span class="name">span</span> <span class="attr">class</span>=<span class="string">"split"</span> <span class="attr">ng-if</span>=<span class="string">"!$first&amp;&amp;!$last"</span>&gt;</span><span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">              <span class="tag">&lt;<span class="name">span</span> <span class="attr">class</span>=<span class="string">"button"</span> <span class="attr">ng-click</span>=<span class="string">"changeSort(students, si, 1, 'sort')"</span> <span class="attr">ng-if</span>=<span class="string">"!$last"</span>&gt;</span>下移<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">td</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;/<span class="name">tr</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">tbody</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">tfoot</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">tr</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">td</span> <span class="attr">colspan</span>=<span class="string">"6"</span>&gt;</span>总数量: <span class="tag">&lt;<span class="name">span</span> <span class="attr">ng-bind</span>=<span class="string">"persons.length"</span>&gt;</span><span class="tag">&lt;/<span class="name">span</span>&gt;</span><span class="tag">&lt;/<span class="name">td</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;/<span class="name">tr</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">tfoot</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">table</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">p</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">lable</span>&gt;</span>姓名: <span class="tag">&lt;<span class="name">input</span> <span class="attr">ng-model</span>=<span class="string">"newStu.name"</span> <span class="attr">type</span>=<span class="string">"text"</span>/&gt;</span><span class="tag">&lt;/<span class="name">lable</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">p</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">lable</span>&gt;</span>性别: <span class="tag">&lt;<span class="name">input</span> <span class="attr">ng-model</span>=<span class="string">"newStu.gender"</span> <span class="attr">type</span>=<span class="string">"radio"</span> <span class="attr">name</span>=<span class="string">"gender"</span> <span class="attr">value</span>=<span class="string">"男"</span>/&gt;</span>男&amp;nbsp;&amp;nbsp;&amp;nbsp;<span class="tag">&lt;<span class="name">input</span></span><br><span class="line">              <span class="attr">ng-model</span>=<span class="string">"newStu.gender"</span> <span class="attr">type</span>=<span class="string">"radio"</span> <span class="attr">name</span>=<span class="string">"gender"</span> <span class="attr">value</span>=<span class="string">"女"</span>/&gt;</span>女</span><br><span class="line">          <span class="tag">&lt;/<span class="name">lable</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">p</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">lable</span>&gt;</span>年龄: <span class="tag">&lt;<span class="name">input</span> <span class="attr">ng-model</span>=<span class="string">"newStu.age"</span> <span class="attr">type</span>=<span class="string">"number"</span>/&gt;</span><span class="tag">&lt;/<span class="name">lable</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">button</span> <span class="attr">ng-click</span>=<span class="string">"add(newStu)"</span>&gt;</span>添加<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="javascript"></span><br><span class="line">      <span class="keyword">var</span> myApp = angular.module(<span class="string">'myApp'</span>, []);</span><br><span class="line">      myApp.filter(<span class="string">'ngRepeatFinishEveryTime'</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$timeout</span>) </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="function"><span class="keyword">function</span> (<span class="params">data, eventName</span>) </span>&#123;</span><br><span class="line">          <span class="keyword">var</span> me = <span class="keyword">this</span>;</span><br><span class="line">          <span class="keyword">var</span> flagProperty = <span class="string">'__finishedRendering__'</span>;</span><br><span class="line">          <span class="keyword">if</span> (!data) data = &#123;&#125;;</span><br><span class="line">          <span class="keyword">if</span> (!data[flagProperty]) &#123;</span><br><span class="line">            <span class="built_in">Object</span>.defineProperty(data, flagProperty, &#123;</span><br><span class="line">              enumerable: <span class="literal">false</span>,</span><br><span class="line">              configurable: <span class="literal">true</span>,</span><br><span class="line">              writable: <span class="literal">false</span>,</span><br><span class="line">              value: &#123;&#125;</span><br><span class="line">            &#125;);</span><br><span class="line">            $timeout(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">              <span class="keyword">delete</span> data[flagProperty];</span><br><span class="line">              me.$emit(eventName ? eventName : <span class="string">"ngRepeatFinishEveryTime"</span>);</span><br><span class="line">            &#125;, <span class="number">0</span>, <span class="literal">false</span>);</span><br><span class="line">          &#125;</span><br><span class="line">          <span class="keyword">return</span> data;</span><br><span class="line">        &#125;;</span><br><span class="line">      &#125;);</span><br><span class="line">      myApp.controller(<span class="string">'userCtrl'</span>, <span class="function"><span class="keyword">function</span> (<span class="params">$scope</span>) </span>&#123;</span><br><span class="line">        $scope.newStu = &#123;</span><br><span class="line">          name: <span class="string">"jicemoon"</span>,</span><br><span class="line">          gender: <span class="string">"男"</span>,</span><br><span class="line">          age: <span class="number">19</span></span><br><span class="line">        &#125;</span><br><span class="line">        $scope.persons = [&#123;</span><br><span class="line">          id: <span class="string">"161112001"</span>,</span><br><span class="line">          sort: <span class="number">0</span>,</span><br><span class="line">          name: <span class="string">"赵子龙"</span>,</span><br><span class="line">          gender: <span class="string">"男"</span>,</span><br><span class="line">          age: <span class="number">18</span></span><br><span class="line">        &#125;, &#123;</span><br><span class="line">          id: <span class="string">"161112002"</span>,</span><br><span class="line">          sort: <span class="number">2</span>,</span><br><span class="line">          name: <span class="string">"吕布"</span>,</span><br><span class="line">          gender: <span class="string">"男"</span>,</span><br><span class="line">          age: <span class="number">18</span></span><br><span class="line">        &#125;, &#123;</span><br><span class="line">          id: <span class="string">"161112003"</span>,</span><br><span class="line">          sort: <span class="number">1</span>,</span><br><span class="line">          name: <span class="string">"貂蝉"</span>,</span><br><span class="line">          gender: <span class="string">"女"</span>,</span><br><span class="line">          age: <span class="number">18</span></span><br><span class="line">        &#125;, &#123;</span><br><span class="line">          id: <span class="string">"161112004"</span>,</span><br><span class="line">          sort: <span class="number">3</span>,</span><br><span class="line">          name: <span class="string">"孙尚香"</span>,</span><br><span class="line">          gender: <span class="string">"女"</span>,</span><br><span class="line">          age: <span class="number">18</span></span><br><span class="line">        &#125;];</span><br><span class="line">        $scope.add = <span class="function"><span class="keyword">function</span> (<span class="params">obj</span>) </span>&#123;</span><br><span class="line">          obj = <span class="built_in">JSON</span>.parse(<span class="built_in">JSON</span>.stringify(obj));</span><br><span class="line">          <span class="keyword">var</span> lens = $scope.persons.length + <span class="number">1</span>;</span><br><span class="line">          obj.id = <span class="string">"161112"</span> + (<span class="string">"000"</span> + lens).substring((<span class="string">''</span> + lens).length);</span><br><span class="line">          obj.sort = lens - <span class="number">1</span>;</span><br><span class="line">          $scope.persons.push(obj);</span><br><span class="line">        &#125;</span><br><span class="line">        $scope.changeSort = <span class="function"><span class="keyword">function</span> (<span class="params">arr, index, up, attr</span>) </span>&#123;</span><br><span class="line">          <span class="keyword">var</span> temp;</span><br><span class="line">          temp = arr[index].sort;</span><br><span class="line">          arr[index][attr] = arr[index + up][attr];</span><br><span class="line">          arr[index + up][attr] = temp;</span><br><span class="line">          <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125;;</span><br><span class="line">        $scope.$on(<span class="string">"studentsRepeatFinish"</span>, <span class="function"><span class="keyword">function</span> (<span class="params">repeatFinishedEvent</span>) </span>&#123;</span><br><span class="line">          <span class="built_in">console</span>.log(<span class="string">"data update &amp; repeat render complete"</span>);</span><br><span class="line">        &#125;)</span><br><span class="line">      &#125;)</span><br><span class="line">    </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure></p>
<p>完整实例, 请点击一下链接进行下载<br>链接: <a href="http://pan.baidu.com/s/1c7eRRg" target="_blank" rel="external">http://pan.baidu.com/s/1c7eRRg</a>   密码: 34gp</p>

      
    </div>
    
  </div>
  
    


    <nav id="article-nav">
        
        
            <div id="article-nav-older" class="article-nav-title">
                <a href="/2016/04/12/ecmascript5-array-method/">
                    ECMAScript 5中的数组方法
                </a>
            </div>
        
    </nav>

  
</article>

    <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录</strong>
    <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#ng-repeat渲染完成事件"><span class="toc-number">1.</span> <span class="toc-text">ng-repeat渲染完成事件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#核心代码"><span class="toc-number">2.</span> <span class="toc-text">核心代码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#实例"><span class="toc-number">3.</span> <span class="toc-text">实例</span></a></li></ol>
</div>
<style>
    .left-col .switch-btn {
        display: none;
    }
    .left-col .switch-area {
        display: none;
    }
</style>

<input type="button" id="tocButton" value="隐藏目录"  title="点击按钮隐藏或者显示文章目录">
<script>
    var valueHide = "隐藏目录";
    var valueShow = "显示目录";

    if ($(".left-col").is(":hidden")) {
        $("#tocButton").attr("value", valueShow);
    }

    $("#tocButton").click(function() {
        if ($("#toc").is(":hidden")) {
            $("#tocButton").attr("value", valueHide);
            $("#toc").slideDown(320);
            $(".switch-btn, .switch-area").fadeOut(300);
        }
        else {
            $("#tocButton").attr("value", valueShow);
            $("#toc").slideUp(350);
            $(".switch-btn, .switch-area").fadeIn(500);
        }
    })

    if ($(".toc").length < 1) {
        $("#toc, #tocButton").hide();
        $(".switch-btn, .switch-area").show();
    }
</script>






    
      <div class="duoshuo" id="comments">
    <!-- 多说评论框 start -->
    <div class="ds-thread" data-thread-key="2016/06/09/ng-repeat-finish-render-every-time/" data-title="AngularJS中ng-repeat渲染完成事件[2]" data-url="http://jicemoon.github.io/2016/06/09/ng-repeat-finish-render-every-time/"></div>
    <!-- 多说评论框 end -->
    <!-- 多说公共JS代码 start (一个网页只需插入一次) -->
    <script type="text/javascript">
    var duoshuoQuery = {short_name:"jicemoon"};
    (function() {
        var ds = document.createElement('script');
        ds.type = 'text/javascript';ds.async = true;
        ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
        ds.charset = 'UTF-8';
        (document.getElementsByTagName('head')[0] 
         || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
    </script>
    <!-- 多说公共JS代码 end -->
</div>

    




    <div class="scroll" id="post-nav-button">
        
            <a href="/" title="回到主页"><i class="fa fa-home"></i></a>
        

        <a title="文章列表"><i class="fa fa-bars"></i><i class="fa fa-times"></i></a>

        
            <a href="/2016/04/12/ecmascript5-array-method/" title="下一篇: ECMAScript 5中的数组方法">
                <i class="fa fa-angle-right"></i>
            </a>
        
    </div>

    <ul class="post-list"><li class="post-list-item"><a class="post-list-link" href="/2016/06/09/ng-repeat-finish-render-every-time/">AngularJS中ng-repeat渲染完成事件[2]</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/12/ecmascript5-array-method/">ECMAScript 5中的数组方法</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/01/AngularJS-repeat-finished/">AngularJS中ng-repeat渲染完成事件[1]和中间变量的引用</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/04/01/Javascript-date-format/">Javascript-date-format</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/03/30/javascriptLoad/">Web动态加载JS外部文件(script标签)</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/03/18/js-bit-operator/">Javascript中的位运算符</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/03/16/HexoDocs/">Hexo Docs基本用法</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/03/14/CSS-middle/">CSS垂直居中</a></li><li class="post-list-item"><a class="post-list-link" href="/2016/03/11/html5-game-hardestGame/">HTML5游戏 - 见缝插针</a></li></ul>
    <script>
        $(".post-list").addClass("toc-article");
        $(".post-list-item a").attr("target","_blank");
        $("#post-nav-button > a:nth-child(2)").click(function() {
            $(".fa-bars, .fa-times").toggle();
            $(".post-list").toggle(300);
            if ($(".toc").length > 0) {
                $("#toc, #tocButton").toggle(200, function() {
                    if ($(".switch-area").is(":visible")) {
                        $("#toc, .switch-btn, .switch-area").toggle();
                        $("#tocButton").attr("value", valueHide);
                        }
                    })
            }
            else {
                $(".switch-btn, .switch-area").fadeToggle(300);
            }
        })
    </script>




    <script>
        
    </script>
</div>
      <footer id="footer">
    <div class="outer">
        <div id="footer-info">
            <div class="footer-left">
                &copy; 2016 jicemoon
            </div>
            <div class="footer-right">
                <a href="http://hexo.io/" target="_blank" title="快速、简洁且高效的静态博客框架">Hexo</a>  Theme <a href="https://github.com/MOxFIVE/hexo-theme-yelee" target="_blank" title="简而不减双栏 Hexo 博客主题">Yelee</a> by MOxFIVE
            </div>
        </div>
        
            <div class="visit">
                
                    <span id="busuanzi_container_site_pv" style='display:none'>
                        <span id="site-visit" >本站到访数: 
                            <span id="busuanzi_value_site_uv"></span>
                        </span>
                    </span>
                
                
                    <span>, </span>
                
                
                    <span id="busuanzi_container_page_pv" style='display:none'>
                        <span id="page-visit">本页阅读量: 
                            <span id="busuanzi_value_page_pv"></span>
                        </span>
                    </span>
                
            </div>
        
    </div>
</footer>
    </div>
    
<script data-main="/js/main.js" src="//cdn.bootcss.com/require.js/2.1.22/require.min.js"></script>

    <script>
        $(document).ready(function() {
            var iPad = window.navigator.userAgent.indexOf('iPad');
            if (iPad > -1 || $(".left-col").css("display") === "none") {
                var bgColorList = ["#9db3f4", "#414141", "#e5a859", "#f5dfc6", "#c084a0", "#847e72", "#cd8390", "#996731"];
                var bgColor = Math.ceil(Math.random() * (bgColorList.length - 1));
                $("body").css({"background-color": bgColorList[bgColor], "background-size": "cover"});
            }
            else {
                var backgroundnum = 5;
                var backgroundimg = "url(/background/bg-x.jpg)".replace(/x/gi, Math.ceil(Math.random() * backgroundnum));
                $("body").css({"background": backgroundimg, "background-attachment": "fixed", "background-size": "cover"});
            }
        })
    </script>




<div class="scroll" id="scroll">
    <a href="#" title="返回顶部"><i class="fa fa-arrow-up"></i></a>
    <a href="#comments" title="查看评论"><i class="fa fa-comments-o"></i></a>
    <a href="#footer" title="转到底部"><i class="fa fa-arrow-down"></i></a>
</div>

<script>
    $(document).ready(function() {
        if ($("#comments").length < 1) {
            $("#scroll > a:nth-child(2)").hide();
        };
    })
</script>


<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>
  </div>
</body>
</html>